$OpenBSD: patch-kanjips_kanjips_c,v 1.4 2017/04/22 04:53:17 jsg Exp $
--- kanjips/kanjips.c.orig	Wed Jan 17 04:20:29 1990
+++ kanjips/kanjips.c	Sat Apr 22 14:48:30 2017
@@ -18,6 +18,8 @@ unsigned char *zs;	/* for state machine zztrans() */
 FILE *infile = stdin,*outfile = stdout;
 
 extern Font *openfont();
+int header_done = 0;
+static void forgetdef();
 
 main(argc,argv) char **argv;
 {
@@ -39,18 +41,23 @@ main(argc,argv) char **argv;
 	}
 	zzinit(0);	/* reset the state machine */
 	for(line = 0; fgets(linebuf,BUFMAX,infile); line++){
-		if(line == 1){
-			outheader();
+		if (line == 0 && strmatch(linebuf, "%!")){
+			fprintf(outfile,"%s",linebuf);
+			continue;
 		}
 		if(strmatch(linebuf,CDSTR)){
 			fprintf(outfile,"%s",linebuf);
 			conform(linebuf);
+			continue;
 		}
-		else { /* normal line */
-			for(zs=linebuf; *zs; zs++){
-				zztrans(*zs,0); /* process 1 line */
-			}
+		if (!header_done){
+			outheader();
+			header_done = 1;
 		}
+		/* normal line */
+		for(zs=linebuf; *zs; zs++){
+			zztrans(*zs,0); /* process 1 line */
+		}
 	}
 }
 conform(s) unsigned char *s;
@@ -64,6 +71,10 @@ conform(s) unsigned char *s;
 	s += strlen(CDSTR);
 	while(isspace(*s)) s++;
 	if(strmatch(s,DFSTR)){ /* %%DocumentFonts */
+		if (!header_done){
+			outheader();
+			header_done = 1;
+		}
 		s += strlen(DFSTR);
 		forgetfont();
 		for(nfonts = 0; *s && nfonts < MAXFONTS; s++){
@@ -103,7 +114,7 @@ forgetfont()
 static int registcodes[MAXREGIST];	/* remembered font codes */
 static int ncodes = 0;			/* number of remembered fonts */
 
-static regist(code) int code;
+static void regist(code) int code;
 {
 	register i;
 	for(i=0; i<ncodes; i++){
@@ -116,7 +127,7 @@ static regist(code) int code;
 	fprintf(outfile,"end\n");
 	registcodes[ncodes++] = code;
 }
-static forgetdef()
+static void forgetdef()
 {
 	ncodes = 0;	/* forget about sent data */
 }
